package com.songlanyun.modules.coupon.controller.api;

import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import com.songlanyun.modules.account.controller.common.AbstractApiController;
import com.songlanyun.modules.coupon.model.dto.SelectPlatformCouponDTO;
import com.songlanyun.modules.coupon.model.dto.SelectShopCouponDTO;
import com.songlanyun.modules.coupon.model.vo.CouponEntityVo;
import com.songlanyun.modules.coupon.model.vo.CouponReceiveRecordVo;
import com.songlanyun.modules.coupon.service.CouponReceiveRecordService;
import com.songlanyun.modules.coupon.service.ISelectPlatformCouponService;
import com.songlanyun.modules.coupon.service.ISelectShopCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 我的优惠券
 *
 * @author lubo
 * @email sunlightcs@gmail.com
 * @date 2022-07-05 15:20:02
 */
@RestController
@RequestMapping("api/select")
public class CouponSelectApiController extends AbstractApiController {
    @Autowired
    private ISelectShopCouponService selectShopCouponService;

    @Autowired
    private ISelectPlatformCouponService selectPlatformCouponService;

    /**
     * 下单时选择店铺券
     */
    @PostMapping("/shopcoupon")
    //@RequiresPermissions("coupon:couponreceiverecord:list")
    public R shopcoupon(@RequestBody SelectShopCouponDTO dto){
        Long userId = getUserId(true);

        List<CouponReceiveRecordVo> couponEntityVos = selectShopCouponService.selectShopCoupons(userId, dto);
        return R.ok().put("list", couponEntityVos);
    }


    /**
     * 下单时选择平台券
     */
    @PostMapping("/platcoupon")
    //@RequiresPermissions("coupon:couponreceiverecord:list")
    public R platcoupon(@RequestBody SelectPlatformCouponDTO dto){
        Long userId = getUserId(true);
        List<CouponReceiveRecordVo> couponEntityVos = selectPlatformCouponService.selectPlatfromCoupons(userId, dto);
        return R.ok().put("list", couponEntityVos);
    }


}
